<?php
/**
 * Created by PhpStorm.
 * User: Tin
 * Date: 6/27/14
 * Time: 10:18 PM
 */

namespace App\Library\System\Model;

use App\Library\System\Model;

class StyleModel extends Model
{
    private static $static_style;

    public static function getInstance()
    {
        if (!self::$static_style) {
            self::$static_style = new StyleModel();
        }

        return self::$static_style;
    }

    public function createStyle($type, $name, $content)
    {
        if ($this->loadStyle($type, $name) != null)
            $this->non($this->update()
                ->table('cache_css')
                ->set(array('content' => $content))
                ->where(array('type' => $type,
                              'name' => $name)));

        else
            $this->non($this->insert()
                ->into('cache_css')
                ->values(array(
                        'type'    => $type,
                        'name'    => $name,
                        'content' => $content
                    )
                ));
    }

    public function loadStyle($type, $name)
    {

        return $this->one($this->select()
            ->from('cache_css')
            ->columns(array('content'))
            ->where(array(
                    'type' => $type,
                    'name' => $name
                )
            ));
    }
} 